<?php
function litimgurls($imgid=0)
{
    global $lit_imglist,$dsql;
    //获取附加表
    $row = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c 
                                                            ON a.channel=c.id where a.id='$imgid'");
    $addtable = trim($row['addtable']);
    
    //获取图片附加表imgurls字段内容进行处理
    $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'");
    
    //调用inc_channel_unit.php中ChannelUnit类
    $ChannelUnit = new ChannelUnit(2,$imgid);
    
    //调用ChannelUnit类中GetlitImgLinks方法处理缩略图
    $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
    
    //返回结果
    return $lit_imglist;
}
//这个函数用于根据mid获取用户的头衔
function getUserTitleByMid($mid)
{
   global $dsql; 
    $row = $dsql->GetOne("SELECT experience from `#@__member` where mid='$mid' ");
    $experience=$row['experience'];
	$arr = $dsql->GetOne("SELECT titles from `#@__scores` where integral <='$experience' order by integral desc");
    $title=$arr['titles'];
	
    echo $title;
 }
 //这个函数用于根据mid获取用户的等级图，这个数字可以用着它相应的图片的获取
function getUserIconLevelByMid($mid)
{
   global $dsql; 
    $row = $dsql->GetOne("SELECT experience from `#@__member` where mid='$mid' ");
    $experience=$row['experience'];
	$arr = $dsql->GetOne("SELECT icon from `#@__scores` where integral <='$experience' order by integral desc");
    $icon=$arr['icon'];
	
    echo $icon;
 }
 //这个函数用于根据userid获取用户的头衔
function getUserTitleByUserId($userid)
{
   global $dsql; 
    $row = $dsql->GetOne("SELECT experience from `#@__member` where userid='$userid' ");
    $experience=$row['experience'];
	$arr = $dsql->GetOne("SELECT titles from `#@__scores` where integral <='$experience' order by integral desc");
    $title=$arr['titles'];
	
    echo $title;
 }
  //这个函数用于根据userid于获取用户的等级，这个等级还可以用于等级图片的获取
function getIconLevelByUserId($userid)
{
   global $dsql; 
    $row = $dsql->GetOne("SELECT experience from `#@__member` where userid='$userid' ");
    $experience=$row['experience'];
	$arr = $dsql->GetOne("SELECT icon from `#@__scores` where integral <='$experience' order by integral desc");
    $iconLevel=$arr['icon'];
	
    echo $iconLevel;
 }
   //这个函数用于根据usedri于获取用户的经验
function getExpByUserId($userid)
{
   global $dsql; 
    $row = $dsql->GetOne("SELECT experience from `#@__member` where userid='$userid' ");
    $experience=$row['experience'];
	
    echo $experience;
 }
 
 /**
	userid是用户id
*/
function getLevelIcon($userid,$mid){
	/*
	1		4		16		64		256
	
	星星		月亮		太阳		皇冠		金冠
	*/
	
	
	$m="";//结果
	$n=0;//余数
	$jg=256;//金冠
	$hg=64;//皇冠
	$ty=16;//太阳
	$yl=4;//月亮
	
	if($userid=="noneed"){
		global $dsql; 
		$row = $dsql->GetOne("SELECT experience from `#@__member` where mid='$mid' ");
		$experience=$row['experience'];
		$arr = $dsql->GetOne("SELECT icon from `#@__scores` where integral <='$experience' order by integral desc");
		$icon=$arr['icon'];
		$x=$icon;
	}else{
		 global $dsql; 
		$row = $dsql->GetOne("SELECT experience from `#@__member` where userid='$userid' ");
		$experience=$row['experience'];
		$arr = $dsql->GetOne("SELECT icon from `#@__scores` where integral <='$experience' order by integral desc");
		$iconLevel=$arr['icon'];
		$x=$iconLevel;
	}


	if($x<=1023){
	//1023为目前的最大等级值
	 if($x/$jg>=1)
	 {
		//m+=floor(x/jg)+"金冠";
		$m.=getIconStr(floor($x/$jg),"jg");
		$n=$x%$jg;
		if($n/$hg>=1)
		{
			$m.=getIconStr(floor($n/$hg),"hg");
			$n=$n%$hg;
			if($n/$ty>=1)
			{
				$m.=getIconStr(floor($n/$ty),"ty");
				$n=$n%$ty;
				if($n/$yl>=1)
				{
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}else
			{
				if($n/$yl>=1){
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}
		}else
		{
			if($n/$ty>=1)
			{
				$m.=getIconStr(floor($n/$ty),"ty");
				$n=$n%$ty;
				if($n/$yl>=1)
				{
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}else
			{
				if($n/$yl>=1){
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}
		}
	 }else
	 {
	 	
		if($x/$hg>=1)
		{
			$m.=getIconStr(floor($x/$hg),"hg");
			$n=$x%$hg;
			if($n/$ty>=1)
			{
				$m.=getIconStr(floor($n/$ty),"ty");
				$n=$n%$ty;
				if($n/$yl>=1)
				{
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}else
			{
				if($n/$yl>=1){
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}
		}else
		{
			if($x/$ty>=1)
			{
				$m.=getIconStr(floor($x/$ty),"ty");
				$n=$x%$ty;
				if($n/$yl>=1)
				{
					$m.=getIconStr(floor($n/$yl),"yl");
					$n=$n%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($n,"xx");
				}
			}else
			{
				if($x/$yl>=1){
					$m.=getIconStr(floor($x/$yl),"yl");
					$n=$x%$yl;
					$m.=getIconStr($n,"xx");
				}else
				{
					$m.=getIconStr($x,"xx");
				}
			}
		}
	 }//jg else结束
	}else{
		$m.="恭喜您达到顶级";
	}
 echo $m;
}

/**
	level---等级图片的个数
	category--星星月亮种类
*/
function getIconStr($level,$category){
 $jgurl="../images/userLevelIcons/jg.gif";
 $hgurl="../images/userLevelIcons/hg.gif";
 $tyurl="../images/userLevelIcons/ty.jpg";
 $ylurl="../images/userLevelIcons/yl.jpg";
 $xxurl="../images/userLevelIcons/xx.jpg";
 $imgStr="";
 if($category=="jg"){
 	for($i=0;$i<$level;$i++){
		$imgStr.="<img src='".$jgurl."'/>";
	}
 }
 else if($category=="hg"){
 	for($i=0;$i<$level;$i++){
		$imgStr.="<img src='".$hgurl."'/>";
	}
 }
 else if($category=="ty"){
 	for($i=0;$i<$level;$i++){
		$imgStr.="<img src='".$tyurl."'/>";
	}
 }
 else if($category=="yl"){
 	for($i=0;$i<$level;$i++){
		$imgStr.="<img src='".$ylurl."'/>";
	}
 }
 else if($category=="xx"){
 	for($i=0;$i<$level;$i++){
		$imgStr.="<img src='".$xxurl."'/>";
	}
 }else{
 	$imgStr.="对不起没有找到图片，请联系管理员！";
 }
 
 echo $imgStr;
}

/***************** 以下信息用于淘客调用**********************/
